package com.wenda.admin.constant;


import com.wenda.admin.vo.SelectNode;

import java.util.ArrayList;
import java.util.List;

public enum UserTypeEnum implements IConvertable {
    SUPER_ADMIN(10, "超级管理员"),
    STUDENT(20, "学生"),
    TEACHER(30, "教师"),
    SECURITY(40, "安保"),
    ;
    private int id;
    private String name;

    private UserTypeEnum(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public static List<SelectNode> select2(){
        UserTypeEnum[] values = UserTypeEnum.values();
        List<SelectNode> list = new ArrayList<>(values.length);
        for(UserTypeEnum t:values){
            list.add(new SelectNode(String.valueOf(t.getId()),t.getName()));
        }
        return list;
    }

    @Override
    public int getId() {
        return id;
    }

    @Override
    public String getName() {
        return name;
    }

    public static String getNameById(Integer id) {
        if (id != null) {
            for (UserTypeEnum t : UserTypeEnum.values()) {
                if (t.getId() == id) {
                    return t.getName();
                }
            }
        }
        return "";
    }

    public static UserTypeEnum toEnum(Integer id) {
        UserTypeEnum ret = null;
        if (id != null) {
            for (UserTypeEnum t : UserTypeEnum.values()) {
                if (t.getId() == id) {
                    ret = t;
                    break;
                }
            }
        }
        return ret;
    }
}
